#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
void Maxarr(int arr1[], int arr2[], int sz1, int sz2)
{
	int i = 0;
	int j = 0;
	int n = 0;
	for (i = 0; i < sz1; i++)
	{
		if (n == arr1[i])
		{
			break;
		}
		for (j = 0; j < sz2; j++)
		{
			if (arr1[i] == arr2[j])
			{
				n = arr2[j];
				printf("%d ", arr1[i]);
				break;
			}
		}

	}
}

int main()
{
	int arr1[3];
	int arr2[5];
	for (int i = 0; i < 3; i++)
	{
		scanf("%d", &arr1[i]);
	}
	for (int i = 0; i < 5; i++)
	{
		scanf("%d", &arr2[i]);
	}
	int sz1 = sizeof(arr1) / sizeof(arr1[0]);
	int sz2 = sizeof(arr2) / sizeof(arr2[0]);
	Maxarr(arr1, arr2, sz1, sz2);
    return 0;
}